/**
 * Title: DataCheckUtil.java
 * Description:
 * Copyright: Copyright (c) 2008
 * Company:深圳彩讯科技有限公司
 * Author 罗旭东 (hi@luoxudong.com)
 * Date 2013-8-14 上午10:08:26
 * Version 1.0 
 */
package com.luoxudong.phonenumber.service.utils;

import com.luoxudong.phonenumber.service.exception.PhoneNumberExceptionCode;

/** 
 * ClassName: HttpDataCheckUtil 
 * Description:数据验证
 * Create by 罗旭东
 * Date 2013-8-14 上午10:08:26 
 */
public class DataCheckUtil {
	/**
	 * 
	 * @description:根据错误码转换成响应提示信息
	 * @param errorCode
	 * @return
	 * String
	 * @throws
	 */
	public static String errorCodeCheck(int errorCode)
	{
		String errorMsg = null;
		
		if (errorCode == PhoneNumberExceptionCode.httpRequestException.getErrorCode())//网络请求异常
		{
			errorMsg = "无法连接网络";
		} else if (errorCode == PhoneNumberExceptionCode.httpResponseException.getErrorCode()){//http请求返回异常
			errorMsg = "返回数据错误";
		} else if (errorCode == PhoneNumberExceptionCode.unknownHostException.getErrorCode()){//无法解析主机
			errorMsg = "无法连接到服务器";
		} else if (errorCode == PhoneNumberExceptionCode.httpSocketException.getErrorCode()){
			errorMsg = "网络异常";
		} else if (errorCode == PhoneNumberExceptionCode.socketTimeoutException.getErrorCode()){
			errorMsg = "网络异常";
		} else if (errorCode == PhoneNumberExceptionCode.invalidJsonString.getErrorCode()){
			errorMsg = "返回数据错误";
		}
		
		if (/*MetaDataUtil.isRelease() &&*/ errorMsg != null && !"".equals(errorMsg))
		{
			errorMsg = errorMsg + "[" + errorCode + "]";
		}
		
		return errorMsg;
	}
	
	/**
	 * 
	 * @description: 根据返回的错误信息转换成错误码
	 * @param codeMsg 需要转成错误码的字符串信息
	 * @return
	 * int
	 * @throws
	 */
	public static int httpResponseDataCheck(String codeMsg)
	{
		int errorCode = PhoneNumberExceptionCode.defaultExceptionCode.getErrorCode();
		
		if (codeMsg == null || "".equals(codeMsg))
		{
			return errorCode;
		}
		
		return errorCode;
	}
}
